package cn.leon.controller;

import cn.leon.common.pojo.EasyUITreeNode;
import cn.leon.common.pojo.TaotaoResult;
import cn.leon.content.service.ContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ContenCategoryController {
    @Autowired
    private ContentCategoryService contentCategoryService;

    @RequestMapping("/content/category/list")
    @ResponseBody
    public List<EasyUITreeNode> getContentCatList(@RequestParam(value = "id",defaultValue = "0")long parentId){
        List<EasyUITreeNode> easyUITreeNodeList = contentCategoryService.getContentCategory(parentId);
        return easyUITreeNodeList;
    }

    @RequestMapping("/content/category/create")
    @ResponseBody
    public TaotaoResult insertContentCat(long parentId, String name) {
        TaotaoResult taotaoResult = contentCategoryService.addContentCategory(parentId, name);
        return taotaoResult;
    }

    @RequestMapping("/content/category/update")
    @ResponseBody
    public TaotaoResult updateContentCat(long id, String name) {
        TaotaoResult taotaoResult = contentCategoryService.updateContentCategory(id, name);
        return taotaoResult;
    }

    @RequestMapping("/content/category/delete")
    @ResponseBody
    public TaotaoResult deleteContentCat(long id){
        TaotaoResult taotaoResult = contentCategoryService.deleteContentCategory(id);
        return taotaoResult;
    }
}
